----------------------------------------------------------------------------------- -- Sidor etc binding ----------------------------------------------------------------------------------- function bind(obj) obj:bind_object(trader_object_binder(obj)) end ------------------------------------------------------------------------------------ class "trader_object_binder" (object_binder) function trader_object_binder:__init(obj) super(obj) self.loaded = false end function trader_object_binder:reload(section) object_binder.reload(self, section) end function trader_object_binder:reinit() object_binder.reinit(self) db.storage[self.object:id()] = { } self.st = db.storage[self.object:id()] if (USE_MARSHAL) then RegisterScriptCallback("save_state",self) end end function trader_object_binder:update(delta) object_binder.update(self, delta) -- Апдейт торговли if self.object:clsid() == clsid.script_trader then trade_manager.update(self.object) end local st = db.storage[self.object:id()] if st ~= nil and st.active_scheme ~= nil then xr_logic.try_switch_to_another_section(self.object, st[st.active_scheme], db.actor) end if self.st.active_section ~= nil then xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "update", delta) end end function trader_object_binder:net_spawn(se_abstract) if not object_binder.net_spawn(self, se_abstract) then return false end if not self.object:alive() then return true end local se_obj = alife_object(self.object:id()) if not (se_obj) then return false end db.add_obj(self.object) if self.object:clsid() == clsid.script_trader then --self.object:set_trader_global_anim("idle_spinka") smart_terrain.setup_gulag_and_logic_on_spawn( self.object, self.st, se_obj, modules.stype_trader, self.loaded) end return true end function trader_object_binder:net_destroy() xr_sound.stop_sounds_by_id(self.object:id()) local st = db.storage[self.object:id()] if st and st.active_scheme then xr_logic.issue_event(self.object, st[st.active_scheme], "net_destroy") end local on_offline_condlist = db.storage[self.object:id()] and db.storage[self.object:id()].overrides and db.storage[self.object:id()].overrides.on_offline_condlist if on_offline_condlist ~= nil then xr_logic.pick_section_from_condlist(db.actor, self.object, on_offline_condlist) end if db.offline_objects[self.object:id()] then db.offline_objects[self.object:id()].level_vertex_id = self.object:level_vertex_id() db.offline_objects[self.object:id()].active_section = db.storage[self.object:id()].active_section end if (USE_MARSHAL) then UnregisterScriptCallback("save_state",self) end db.del_obj(self.object) db.storage[self.object:id()] = nil alife_storage_manager.get_state().game_object[self.object:id()] = nil trade_manager.on_npc_death(self.object) self.object:set_callback(callback.use_object,nil) object_binder.net_destroy(self) end function trader_object_binder:net_save_relevant() return true end function trader_object_binder:save(packet) set_save_marker(packet, "save", false, "trader_object_binder") object_binder.save(self, packet) set_save_marker(packet, "save", true, "trader_object_binder") if (USE_MARSHAL) then return end xr_logic.save_obj(self.object, packet) end function trader_object_binder:load(reader) self.loaded = true set_save_marker(reader, "load", false, "trader_object_binder") object_binder.load(self, reader) set_save_marker(reader, "load", true, "trader_object_binder") if (USE_MARSHAL) then if (self.object) then self:load_state() -- fake because binder not ready when real load_state made end return end xr_logic.load_obj(self.object, reader) end ---------------------------------------------------------------------------------- function trader_object_binder:save_state(m_data) --utils_data.debug_write(strformat("trader_object_binder:save_state %s BEFORE",id)) local id = self.object and self.object:id() local st = id and db.storage[id] if not (st) then return end local state = alife_storage_manager.get_game_object_state(self.object,true) state.xr_logic = empty_table(state.xr_logic) --state.xr_logic.job_ini = st.job_ini state.xr_logic.ini_filename = st.ini_filename state.xr_logic.section_logic = st.section_logic state.xr_logic.active_section = st.active_section state.xr_logic.gulag_name = st.gulag_name state.xr_logic.activation_time = (st.activation_time or 0) - time_global() state.xr_logic.activation_game_time = st.activation_game_time --xr_sound.npc_save_state(id,state) db.storage[id].pstor = db.storage[id].pstor or {} --utils_data.debug_write(strformat("trader_object_binder:save_state %s AFTER",id)) end function trader_object_binder:load_state() local state = alife_storage_manager.get_game_object_state(self.object) if not (state and state.xr_logic) then return end local id = self.object:id() db.storage[id] = db.storage[id] or {} local st = db.storage[id] --utils_data.debug_write(strformat("trader_object_binder:load_state %s BEFORE",id)) --st.job_ini = state.xr_logic.job_ini st.loaded_ini_filename = state.xr_logic.ini_filename st.loaded_section_logic = state.xr_logic.section_logic st.loaded_active_section = state.xr_logic.active_section st.loaded_gulag_name = state.xr_logic.gulag_name or "" st.activation_time = state.xr_logic.activation_time and state.xr_logic.activation_time + time_global() or time_global() st.activation_game_time = state.xr_logic.activation_game_time or game.get_game_time() --xr_sound.npc_load_state(id,state) if (state.pstor_all) then db.storage[id].pstor = state.pstor_all state.pstor_all = nil end if (state.pstor_ctime) then db.storage[id].pstor_ctime = state.pstor_ctime m_data.pstor_ctime = nil end --utils_data.debug_write(strformat("trader_object_binder:load_state %s AFTER",id)) end